/**
 * 2010(c) Copyright Oceansoft Information System Co.,LTD. All rights reserved.
 * <p>
 * Compile: JDK 1.6+
 * <p>
 * 版权所有(C)：江苏欧索软件有限公司
 * <p>
 * 公司名称：江苏欧索软件有限公司
 * <p>
 * 公司地址：中国苏州科技城青山路1号
 * <p>
 * 网址: http://www.oceansoft.com.cn
 * <p>
 * 作者: 090922(陈伟)
 * <p>
 * 文件名: com.oceansoft.mobile.econsole.modules.accident.service.AccidentServiceImpl
 * <p>
 * 类产生时间: 2014-08-17 14:41
 * <p>
 * 负责人: 090922(陈伟)
 * <p>
 * Email:javacspring@gmail.com
 * <p>
 * 项目组 : 苏州公安移动门户
 * <p>
 * 部门: 手持技术部
 * <p>
 * <p>
 */
package com.oceansoft.mobile.econsole.modules.accident.service.impl;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oceansoft.mobile.econsole.cache.redis.CacheBaseService;
import com.oceansoft.mobile.econsole.common.constant.Constant;
import com.oceansoft.mobile.econsole.common.util.DateUtil;
import com.oceansoft.mobile.econsole.common.util.FileUtils;
import com.oceansoft.mobile.econsole.common.util.MD5Util;
import com.oceansoft.mobile.econsole.common.util.web.PageUtil;
import com.oceansoft.mobile.econsole.modules.accident.entity.AccidentInfo;
import com.oceansoft.mobile.econsole.modules.accident.entity.AccidentPhoto;
import com.oceansoft.mobile.econsole.modules.accident.persistence.IAccidentMapper;
import com.oceansoft.mobile.econsole.modules.accident.service.IAccidentService;
import com.oceansoft.mobile.econsole.modules.base.entity.ApiPager;
import com.oceansoft.mobile.econsole.modules.base.entity.Pager;
import com.oceansoft.mobile.econsole.modules.base.entity.Query;
import com.oceansoft.mobile.econsole.modules.base.entity.Result;
import com.oceansoft.mobile.econsole.modules.common.persistence.ICommonUtilMapper;
import com.oceansoft.mobile.econsole.modules.member.entity.Member;
import com.oceansoft.mobile.econsole.modules.member.persistence.IMemberMapper;
import com.oceansoft.mobile.econsole.modules.member.service.IMemberService;
import com.oceansoft.mobile.econsole.modules.weixin.service.WeixinQueryService;
import com.oceansoft.mobile.econsole.modules.weixin.service.impl.WeixinQueryServiceImpl;
import com.oceansoft.mobile.econsole.modules.weixin.service.impl.WxMemberServiceImpl;
import com.oceansoft.mobile.econsole.task.sms.SMSUtil;
import com.oceansoft.mobile.econsole.task.sms.ScheduleTasker;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import sun.misc.BASE64Decoder;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.util.*;

import static com.oceansoft.mobile.econsole.common.constant.Constant.*;

/**
 * 事故基本信息业务操作业务组件
 *
 * @author chenw
 * @time 2014-08-17 14:41
 */
@Service
@Transactional
public class AccidentServiceImpl extends CacheBaseService implements IAccidentService {

    private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(AccidentServiceImpl.class);

    private static final int SYNC_CODE_USER_NO_EXISTS = -1;//当前登录用户不存在
    private static final int SYNC_CODE_GET_PWD_FAILURE = 1;//获取网厅密码失败
    private static final int SYNC_CODE_DATA_SYNC_SUCC = 2;//密码匹配成功
    private static final int SYNC_CODE_PWD_MATCH_FAILURE = 3; //密码不与网厅不匹配
    private static final int SYNC_CODE_NO_REQUIRED = 4; //无须同步

    @Resource
    private IAccidentMapper accidentMapper;

    @Resource
    private IMemberService memberService;

    @Resource
    private IMemberMapper memberMapper;

    @Resource
    private ICommonUtilMapper commonUtilMapper;

    @Resource
    private WeixinQueryService weixinQueryService;

    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public Result saveAccidentBaseInfo(MultipartHttpServletRequest request) throws IOException {
        //事故基本信息
        AccidentInfo baseInfo = new AccidentInfo();
        String userId = request.getParameter("userId");  //检测用户是否登录
        if (!StringUtils.hasText(userId))
            return new Result(Result.FAILURE, "当前用户未登录");
        baseInfo.setUserId(userId);//上报用户ID
        //生成事故流水号
        Map<String, String> param = new HashMap<String, String>() {{
            put("serialNum", "");
        }};
//        commonUtilMapper.genAccidentSerialNum(param);
//        baseInfo.setAccidentId(param.get("serialNum"));

        String serialNum = weixinQueryService.getSlbh(com.oceansoft.mobile.econsole.modules.weixin.config.Constant.KCLP);
        baseInfo.setAccidentId(serialNum);
        baseInfo.setCoordinate(request.getParameter("coord"));//经纬度坐标
        baseInfo.setPosition(request.getParameter("position"));//位置文字信息
        baseInfo.setStatus(AccidentInfo.STATUS_WAITTING);
        baseInfo.setOccurTime(new Date());
        baseInfo.setReportTime(new Date());
        accidentMapper.save(baseInfo);
        String photoTaker = request.getParameter("takerName");
        //现场图片信息
        List<MultipartFile> mps = request.getFiles("photo");//附件图片
        if (mps.isEmpty())
            return new Result(Result.FAILURE, "请上传现场图片");
        for (int i = 0; i < mps.size(); i++) {
            MultipartFile mp = mps.get(i);
            AccidentPhoto photo = new AccidentPhoto();
            photo.setPhotoGuid(UUID.randomUUID().toString());
            photo.setUserId(baseInfo.getUserId());
            photo.setCoordinate(baseInfo.getCoordinate());
            photo.setPosition(baseInfo.getPosition());
            photo.setShootTime(DateUtil.millisToDate(request.getParameter("shootTime")));
            photo.setTakerName(request.getParameter("photoTaker"));//拍照人姓名
            photo.setTakerName(photoTaker);
            photo.setPhotoType(i + 5);//5:车头方向照片 6:车尾方向照片 7:碰撞部位照片
            photo.setSize(mp.getSize());
            photo.setFileContent(mp.getBytes());
            photo.setAccidentId(baseInfo.getAccidentId());
            photo.setSuffix(FileUtils.getExtName(mp.getOriginalFilename()));
            String newFileName = String.format("%s%s", photo.getPhotoGuid(), FileUtils.getExtName(mp.getOriginalFilename()));
            String bizParentDir = configInfo.getBizDayDirRelPath(baseInfo.getUserId(), configInfo.getTrafficeDir());
            photo.setFilePath(String.format("%s/%s", bizParentDir, newFileName));
            //存储文件至文件系统
            mp.transferTo(FileUtils.createFile(new File(String.format("%s/%s", configInfo.getFileUploadRootPath(), bizParentDir)), newFileName));
            accidentMapper.savePhoto(photo);
        }
        return new Result(Result.SUCC, baseInfo.getAccidentId(), "提交成功");
    }

    @Override
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public Result saveAccidentPhotosPlace(HttpServletRequest request) throws IOException {
        //事故基本信息
        AccidentInfo baseInfo = new AccidentInfo();
        String userId = request.getParameter("userId");  //检测用户是否登录
        if (!StringUtils.hasText(userId))
            return new Result(Result.FAILURE, "当前用户未登录");
        baseInfo.setUserId(userId);//上报用户ID
        //生成事故流水号
        Map<String, String> param = new HashMap<String, String>() {{
            put("serialNum", "");
        }};
        commonUtilMapper.genAccidentSerialNum(param);
        baseInfo.setAccidentId(param.get("serialNum"));
        baseInfo.setCoordinate(request.getParameter("coord"));//经纬度坐标
        baseInfo.setPosition(request.getParameter("position"));//位置文字信息
        baseInfo.setStatus(AccidentInfo.STATUS_WAITTING);
        baseInfo.setOccurTime(new Date());
        baseInfo.setReportTime(new Date());
        accidentMapper.save(baseInfo);
        String photoTaker = request.getParameter("takerName");
        //现场图片信息
        String[] mps = request.getParameterValues("photo");//附件图片
        if (null == mps || 0 == mps.length)
            return new Result(Result.FAILURE, "请上传现场图片");

        for(int i = 0; i < mps.length; i++){

            BASE64Decoder decoder = new BASE64Decoder();
            // Base64解码
            byte[] bytes = decoder.decodeBuffer(mps[i]);
            for (int j = 0; j < bytes.length; ++j) {
                if (bytes[j] < 0) {// 调整异常数据
                    bytes[j] += 256;
                }
            }

            AccidentPhoto photo = new AccidentPhoto();
            photo.setPhotoGuid(UUID.randomUUID().toString());
            photo.setUserId(baseInfo.getUserId());
            photo.setCoordinate(baseInfo.getCoordinate());
            photo.setPosition(baseInfo.getPosition());
            photo.setShootTime(DateUtil.millisToDate(request.getParameter("shootTime")));
            photo.setTakerName(request.getParameter("photoTaker"));//拍照人姓名
            photo.setTakerName(photoTaker);
            photo.setPhotoType(i + 5);//5:车头方向照片 6:车尾方向照片 7:碰撞部位照片
            photo.setSize(bytes.length);
            photo.setFileContent(bytes);
            photo.setAccidentId(baseInfo.getAccidentId());
            photo.setSuffix(".jpeg");
            String newFileName = String.format("%s%s", photo.getPhotoGuid(), ".jpeg");
            String bizParentDir = configInfo.getBizDayDirRelPath(baseInfo.getUserId(), configInfo.getTrafficeDir());
            photo.setFilePath(String.format("%s/%s", bizParentDir, newFileName));

            File file = FileUtils.createFile(new File(String.format("%s/%s", configInfo.getFileUploadRootPath(), bizParentDir)), newFileName);
            // 生成jpeg图片
            OutputStream out = new FileOutputStream(file);
            out.write(bytes);
            out.flush();
            out.close();

            accidentMapper.savePhoto(photo);
        }

        return new Result(Result.SUCC, baseInfo.getAccidentId(), "提交成功");
    }

    @Override
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public Result processNegotiate(MultipartHttpServletRequest request) throws IOException {
        //更新主表信息
        AccidentInfo baseInfo = accidentMapper.findAccInfoByAccUserIdAndAccident(request.getParameter("userId"), request.getParameter("accidentId"));
        if (null == baseInfo)
            return new Result(Result.FAILURE, "事故信息数据不存在");
        String description = request.getParameter("description");
        if (!StringUtils.hasText(description))
            return new Result(Result.FAILURE, "请选择事故描述信息");
        baseInfo.setDescription(description);
        baseInfo.setAccidentCode(Integer.valueOf(request.getParameter("accidentCode")));

        List<MultipartFile> mps = request.getFiles("photo");//附件图片
        String[] photoStr = request.getParameterValues("photo");//附件图片
        if (mps.isEmpty() && (null == photoStr || photoStr.length == 0)){
            return new Result(Result.FAILURE, "请上传双方当事人驾驶证图片");
        }

        String photoTaker = request.getParameter("takerName");//拍照人姓名
        baseInfo.setHandler(Integer.parseInt(request.getParameter("handler")));
        baseInfo.setStatus(AccidentInfo.STATUS_WAITTING);
        baseInfo.setTelA(request.getParameter("telA"));
        baseInfo.setLpnA(request.getParameter("lpnA"));
        baseInfo.setTelB(request.getParameter("telB"));
        baseInfo.setLpnB(request.getParameter("lpnB"));
        baseInfo.setLicenseA(request.getParameter("licenseA"));
        baseInfo.setLicenseB(request.getParameter("licenseB"));
        //事故责任
        baseInfo.setLiabilityA(Integer.valueOf(request.getParameter("liabilityA")));
        baseInfo.setLiabilityB(Integer.valueOf(request.getParameter("liabilityB")));
        accidentMapper.updateAccidentBaseInfo(baseInfo);
        //保存当事人及对方驾驶证图片信息
        if(!mps.isEmpty()){
            for (int i = 0; i < mps.size(); i++) {
                MultipartFile mp = mps.get(i);
                AccidentPhoto photo = new AccidentPhoto();
                photo.setPhotoGuid(UUID.randomUUID().toString());
                photo.setUserId(baseInfo.getUserId());
                photo.setCoordinate(baseInfo.getCoordinate());
                photo.setPosition(baseInfo.getPosition());
                photo.setShootTime(DateUtil.millisToDate(request.getParameter("shootTime")));
//                photo.setTakerName(request.getParameter("photoTaker"));//拍照人姓名
                photo.setTakerName(photoTaker);
                photo.setPhotoType(i + 3);//第一张照片为本人保险照片(3)，第二张为对方保险照片(4)
                photo.setSize(mp.getSize());
                photo.setFileContent(mp.getBytes());
                photo.setAccidentId(baseInfo.getAccidentId());
                photo.setSuffix(FileUtils.getExtName(mp.getOriginalFilename()));
                String newFileName = String.format("%s%s", photo.getPhotoGuid(), FileUtils.getExtName(mp.getOriginalFilename()));
                String bizParentDir = configInfo.getBizDayDirRelPath(baseInfo.getUserId(), configInfo.getTrafficeDir());
                photo.setFilePath(String.format("%s/%s", bizParentDir, newFileName));
                //存储文件至文件系统
                mp.transferTo(FileUtils.createFile(new File(String.format("%s/%s", configInfo.getFileUploadRootPath(), bizParentDir)), newFileName));
                accidentMapper.savePhoto(photo);
            }
        }

        if(null != photoStr && 0 < photoStr.length){
            for (int i = 0; i < photoStr.length; i++) {
                BASE64Decoder decoder = new BASE64Decoder();
                // Base64解码
                byte[] bytes = decoder.decodeBuffer(photoStr[i]);
                for (int j = 0; j < bytes.length; ++j) {
                    if (bytes[j] < 0) {// 调整异常数据
                        bytes[j] += 256;
                    }
                }

                AccidentPhoto photo = new AccidentPhoto();
                photo.setPhotoGuid(UUID.randomUUID().toString());
                photo.setUserId(baseInfo.getUserId());
                photo.setCoordinate(baseInfo.getCoordinate());
                photo.setPosition(baseInfo.getPosition());
                photo.setShootTime(DateUtil.millisToDate(request.getParameter("shootTime")));
//                photo.setTakerName(request.getParameter("photoTaker"));//拍照人姓名
                photo.setTakerName(photoTaker);
                photo.setPhotoType(i + 3);//第一张照片为本人保险照片(3)，第二张为对方保险照片(4)
                photo.setSize(bytes.length);
                photo.setFileContent(bytes);
                photo.setAccidentId(baseInfo.getAccidentId());
                photo.setSuffix(".jpeg");
                String newFileName = String.format("%s%s", photo.getPhotoGuid(), ".jpeg");
                String bizParentDir = configInfo.getBizDayDirRelPath(baseInfo.getUserId(), configInfo.getTrafficeDir());
                photo.setFilePath(String.format("%s/%s", bizParentDir, newFileName));
                //存储文件至文件系统
                File file = FileUtils.createFile(new File(String.format("%s/%s", configInfo.getFileUploadRootPath(), bizParentDir)), newFileName);
                // 生成jpeg图片
                OutputStream out = new FileOutputStream(file);
                out.write(bytes);
                out.flush();
                out.close();

                accidentMapper.savePhoto(photo);
            }
        }

        //发送短信
        sendMsg(baseInfo);
        return new Result(Result.SUCC, baseInfo.getAccidentId(), "信息上报成功");
    }

    @Override
    public Result getUserAccidentHistory(int userId, int pageIndex, String startdate, String enddate, String cardnum) {
        PageHelper.startPage(pageIndex, Constant.API_PAGE_SIZE, false);
        Page page = (Page<AccidentInfo>) accidentMapper.findAccidentInfoListByPage(userId, 2, startdate, enddate, cardnum);
        ApiPager<AccidentInfo> pager = new ApiPager<AccidentInfo>(page.getTotal(), page.getResult(), pageIndex);
        return new Result(Result.SUCC, pager);
    }

    @Override
    public List<AccidentPhoto> getAccidentPhotos(int usrid, String accident_id) {
        return accidentMapper.findAccidentInsurancePhotos(usrid, accident_id);
    }

    @Override
    @Transactional()
    public Result revokeAccidentReport(@Param("userId") int userId, @Param("accidentId") String accidentId) throws Exception {
        //更新ACCIDENT_INFO表状态为0(已删除)
        int rt = accidentMapper.updateAccidentBaseInfoStatus(userId, accidentId, AccidentInfo.STATUS_DELETE);
        if (rt < 1) {
            return new Result(Result.FAILURE, "事故上报信息撤回失败");
        }
        //删除ACCIDENT_PHOTO表相关事故信息记录，在删除之前将上报图片转储于文件系统中
        List<AccidentPhoto> photos = accidentMapper.findAccPhoto(accidentId, String.valueOf(userId));
        for (AccidentPhoto photo : photos) {
            File file = new File(configInfo.getFileUploadFullPath(photo.getFilePath()));
            if (file.exists())
                continue;
            FileUtils.createFile(new ByteArrayInputStream(photo.getFileContent()), file);
        }
        accidentMapper.deleteAccidentPhoto(userId, accidentId);
        return new Result(Result.SUCC, "事故上报信息撤回成功");
    }

    @Override
    public Map<String, Object> findAccidentInfo(String accidentId) {
        Map<String, Object> data = new HashMap<String, Object>();
        //基本信息
        List<AccidentInfo> listInfo = accidentMapper.findAccInfoByAccId(accidentId);
        String defaultImg = String.format("http://%s:%s/%s%s", configInfo.getAppServerHost(), configInfo.getAppServerPort(), "econsole/resource", "/images/default.jpg");
        if (!listInfo.isEmpty()) {
            AccidentInfo base = listInfo.get(0);
            data.put("baseInfo", base);
            data.put("photoHead", defaultImg);
            data.put("photoTail", defaultImg);
            data.put("photoBody", defaultImg);
            data.put("photoInsureA", defaultImg);
            data.put("photoInsureB", defaultImg);
            data.put("liabilityA", trans2Str(base.getLiabilityA()));
            data.put("liabilityB", trans2Str(base.getLiabilityB()));
        }
        //图片信息
        List<AccidentPhoto> photos = accidentMapper.findAccidentPhotoByOrder(accidentId);
        for (AccidentPhoto photo : photos) {
            String picPath = String.format("%s/%s", configInfo.getFileUploadRootPath(), photo.getFilePath());
            if (!new File(picPath).exists()) {
                try {
                    FileUtils.createFile(new ByteArrayInputStream(photo.getFileContent()), new File(picPath));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            switch (photo.getPhotoType()) {
	            case ACCIDENT_PHOTO_INSURE_A:
	            	data.put("photoInsureA", configInfo.getFileDownloadUrl(photo.getFilePath()));
	            	break;
	            case ACCIDENT_PHOTO_INSURE_B:
	            	data.put("photoInsureB", configInfo.getFileDownloadUrl(photo.getFilePath()));
	            	break;
                case ACCIDENT_PHOTO_HEAD:
                    data.put("photoHead", configInfo.getFileDownloadUrl(photo.getFilePath()));
                    break;
                case ACCIDENT_PHOTO_TAIL:
                    data.put("photoTail", configInfo.getFileDownloadUrl(photo.getFilePath()));
                    break;
                case ACCIDENT_PHOTO_BODY:
                    data.put("photoBody", configInfo.getFileDownloadUrl(photo.getFilePath()));
                    break;
                default:
                    break;
            }
        }
        return data;
    }

    @Override
    public Result doProcessRemote(String userId, String accidentId) {
        AccidentInfo info = accidentMapper.findAccInfoByAccUserIdAndAccident(userId, accidentId);
        if (null == info)
            return new Result(Result.FAILURE, "查询信息不存在");
        info.setHandler(Constant.ACCIDENT_PROCESS_REMOTE);
        info.setStatus(AccidentInfo.STATUS_COMPLETE);
        SMSUtil.sendSMS(info.getAccidentId(), configInfo.getAccidentConfirmSMS(info.getAccidentId()), (info.getTelA() + "," + info.getTelB()));
        if (accidentMapper.updateAccidentBaseInfo(info) > 0)
            return new Result(Result.SUCC, accidentId, "信息提交成功");
        return new Result(Result.FAILURE, "信息提交失败");
    }

    @Override
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public Result doProcessOffice(AccidentInfo accidentInfo) {
        AccidentInfo info = accidentMapper.findAccInfoByAccUserIdAndAccident(accidentInfo.getUserId(), accidentInfo.getAccidentId());
        if (null == info)
            return new Result(Result.FAILURE, "查询信息不存在");
        info.setHandler(Constant.ACCIDENT_PROCESS_OFFICE);
        info.setStatus(AccidentInfo.STATUS_COMPLETE);
        info.setUserId(accidentInfo.getUserId());
        info.setAccidentId(accidentInfo.getAccidentId());
        info.setTelA(accidentInfo.getTelA());
        info.setTelB(accidentInfo.getTelB());
        info.setLicenseA(accidentInfo.getLicenseA());
        info.setLicenseB(accidentInfo.getLicenseB());
        SMSUtil.sendSMS(info.getAccidentId(), configInfo.getAccidentUnConfirm(info.getAccidentId()), (info.getTelA() + "," + info.getTelB()));
        if (accidentMapper.updateAccidentBaseInfo(info) > 0)
            return new Result(Result.SUCC, accidentInfo.getAccidentId(), "信息提交成功");
        return new Result(Result.FAILURE, "信息提交失败");
    }

    @Override
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public AccidentPhoto savePhoto(AccidentPhoto accidentPhoto) {
        accidentMapper.savePhoto(accidentPhoto);
        return accidentPhoto;
    }

    @Override
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public int updatePhoto(AccidentPhoto photo) {
        return accidentMapper.updatePhoto(photo);
    }

    @Override
    public int countSameTypePic(AccidentPhoto photo) {
        return accidentMapper.countSameTypePics(photo);
    }

    @Override
    public Pager<AccidentInfo> findAccMainByCondition(Query query) {
        PageHelper.startPage(query.getPageNum(), query.getNumPerPage(), true);
        Page<AccidentInfo> page = (Page<AccidentInfo>) accidentMapper.findAccMainPageByCondition(query);
        return PageUtil.page2pager(page, query);
    }

    @Override
    public List<AccidentInfo> findAccInfoByAccId(String accidentId, String hostIP) {
        List<AccidentInfo> listInfo = accidentMapper.findAccInfoByAccId(accidentId);
        if (null != listInfo && listInfo.size() > 0) {
            for (AccidentInfo info : listInfo) {
                //获取事故理赔图片
                info.setPhotoList(this.findAccPhoto(accidentId, info.getUserId(), hostIP));
            }
        }
        return listInfo;
    }

    @Override
    public List<AccidentPhoto> findAccPhoto(String accidentId, String userId, String hostIP) {
        List<AccidentPhoto> list = accidentMapper.findAccPhoto(accidentId, userId);
        for (AccidentPhoto photo : list) {
            String picPath = String.format("%s/%s", configInfo.getFileUploadRootPath(), photo.getFilePath());
            if (!new File(picPath).exists()) {
                try {
                    FileUtils.createFile(new ByteArrayInputStream(photo.getFileContent()), new File(picPath));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            photo.setPhotoPath(configInfo.getFileDownloadUrl(photo.getFilePath()));
        }
        return list;
    }

    /**
     * 定责转换
     *
     * @param liability 责任级别
     * @return String
     */
    private String trans2Str(int liability) {
        switch (liability) {
            case 1:
                return "无责";
            case 2:
                return "同责";
            case 3:
                return "全责";
        }
        return "";
    }

    private void sendMsg(AccidentInfo baseInfo) throws IOException {
        String smsNotificationA = configInfo.getAccidentBaseInfo(
                DateUtil.date2String(baseInfo.getOccurTime(), "yyyy年MM月dd日 HH:mm:ss"),
                baseInfo.getPosition(),
                baseInfo.getDescription(),
                baseInfo.getLicenseA(),
                baseInfo.getTelA(),
                baseInfo.getLpnA(),
                trans2Str(baseInfo.getLiabilityA()),
                baseInfo.getLicenseB(),
                baseInfo.getTelB(),
                baseInfo.getLpnB(),
                trans2Str(baseInfo.getLiabilityB())
        );
        String smsNotificationB = configInfo.getAccidentBaseInfo(
                DateUtil.date2String(baseInfo.getOccurTime(), "yyyy年MM月dd日 HH:mm:ss"),
                baseInfo.getPosition(),
                baseInfo.getDescription(),
                baseInfo.getLicenseB(),
                baseInfo.getTelB(),
                baseInfo.getLpnB(),
                trans2Str(baseInfo.getLiabilityB()),
                baseInfo.getLicenseA(),
                baseInfo.getTelA(),
                baseInfo.getLpnA(),
                trans2Str(baseInfo.getLiabilityA())
        );
        SMSUtil.sendSMS(baseInfo.getAccidentId(), smsNotificationA, baseInfo.getTelA());
        SMSUtil.sendSMS(baseInfo.getAccidentId(), smsNotificationB, baseInfo.getTelB());
        new ScheduleTasker(baseInfo.getAccidentId(), new Date(), 600, configInfo, baseInfo, accidentMapper).startTask();
    }

}
